package com.crm.report.service.impl;

import com.crm.custinfo.mapper.CustInfoMapper;
import com.crm.report.mapper.TransactionDataStaticsMapper;
import com.crm.report.service.ICustStaticsService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
/**
 * 客户分配数据统计
 *
 * @author Mr.Wen
 * @date 2024-02-25
 */
@Service
public class CustStaticsServiceImpl implements ICustStaticsService {
    @Autowired
    private CustInfoMapper custInfoMapper;
    @Autowired
    private TransactionDataStaticsMapper transactionDataStaticsMapper;

    /**
     * 机构分配来源统计
     *
     * @param params 获取数据的集合
     * @return 结果
     */
    @Override
    public List<Map<String, Object>> orgDistributeDataStatics(Map<String, Object> params) {
        return custInfoMapper.orgDistributeDataStatics(params);
    }

    /**
     * 渠道分配来源统计
     *
     * @param params 获取数据的集合
     * @return 结果
     */
    @Override
    public List<Map<String, Object>> channelDataStatics(Map<String, Object> params) {
        return custInfoMapper.channelDataStatics(params);
    }

    /**
     * 日内部数据统计报表
     *
     * @param params 获取数据的集合
     * @return 结果
     */
    @Override
    public List<Map<String, Object>> starlevelDataStatics(Map<String, Object> params) {
        return custInfoMapper.starlevelDataStatics(params);
    }
    /**
     * 日内部数据统计报表
     *
     * @param params 获取数据的集合
     * @return 结果
     */
    @Override
    public List<Map<String, Object>> custdebtlimitdataStatics(Map<String, Object> params) {
        return custInfoMapper.custdebtlimitdataStatics(params);
    }

    @Override
    public List<Map<String, Object>> publicCustDataStatics(Map<String, Object> params) {
        return custInfoMapper.publicCustDataStatics(params);
    }
    /**
     * 团队数据统计
     * 20240304: 新增  --
     */
    @Override
    public List<Map<String, Object>> teamCustDataStatics(Map<String, Object> params) {
        int queryType= MapUtils.getIntValue(params, "level");
        if(queryType==6) {
            //个人
            return custInfoMapper.teamCustPersonalDataStatics(params);
        }else  {
            //部门
            return custInfoMapper.teamCustDataStatics(params);
        }
    }
    /**
     * 拨打数据情况统计
     * 20240304: 新增  --
     */
    @Override
    public List<Map<String, Object>> callCustDataStatics(Map<String, Object> params) {
        return custInfoMapper.callCustDataStatics(params);
    }
    /**
     * 成交客户统计报表
     * 20240304: 新增  --
     */
    @Override
    public List<Map<String, Object>> getTransactionDatas(Map<String, Object> params) {
        int reportType=MapUtils.getIntValue(params,"reportType");
        if(reportType==41){
            // 成交客户统计-上门&重复上门
            return transactionDataStaticsMapper.visitDataStatics(params);
        }
        if(reportType==42){
            // 成交客户统计-签约&重复签约
            return transactionDataStaticsMapper.signDataStatics(params);
        }
        if(reportType==43){
            // 成交客户统计-放款&重复放款
            return transactionDataStaticsMapper.loanDataStatics(params);
        }
        if(reportType==44){
            // 成交客户统计-放款&重复放款
            return transactionDataStaticsMapper.introduceDataStatics(params);
        }
        if(reportType==45){
            // 成交客户统计-特殊重复成功
            return transactionDataStaticsMapper.specialDataStatics(params);
        }

        return null;
    }
    /**
     * 成交客户画像
     * 20240304: 新增  --
     */
    @Override
    public List<Map<String, Object>> getTransactionCustPortraitDatas(Map<String, Object> params) {
        int reportType=MapUtils.getIntValue(params,"reportType");
        if(reportType==51){
            // 年龄区间
            return transactionDataStaticsMapper.AgeSectionStatics(params);
        }
        if(reportType==52){
            // 性别
            return transactionDataStaticsMapper.SexSectionStatics(params);
        }
        if(reportType==53){
            // 需求额度区间
            return transactionDataStaticsMapper.NeedAmountSectionStatics(params);
        }
        if(reportType==54){
            // 是否本地人
            return transactionDataStaticsMapper.LocalPersonStatics(params);
        }
        if(reportType==55){
            // 自己放款/扫码放款
            return transactionDataStaticsMapper.SelfLoanStatics(params);
        }

        return null;
    }

}
